//    Copyright (C) 2013  <lugocreation@gmail.com>
//
//    This program is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
package org.jpgolay.me.agency;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
import org.jpgolay.gui.fixed.*;
import org.jpgolay.gui.iconBar.IconBar;
import org.jpgolay.me.util.MEUtility;

public class AgencyGUI extends JInternalFrame {

    public AgencyGUI() {
        jContentPane = null;
        basicMenu = null;
        iconBar = null;
        mainPanel = null;
        agencyListLabelAndComboBox = null;
        jTabbedPane = null;
        addressPanel = null;
        companyLabelAndTextField = null;
        statusLabelAndComboBox = null;
        addrLn1LabelAndTextField = null;
        addrLn2LabelAndTextField = null;
        cityLabelAndTextField = null;
        zipLabelAndTextField = null;
        countryLabelAndTextField = null;
        tel1LabelAndTextField = null;
        fax1LabelAndTextField = null;
        emailLabelAndTextField = null;
        infosPanel = null;
        siretLabelAndTextField = null;
        nafLabelAndTextField = null;
        glnLabelAndTextField = null;
        notesLabelAndTextField = null;
        tel2LabelAndTextField = null;
        tel3LabelAndTextField = null;
        fax2LabelAndTextField = null;
        fax3LabelAndTextField = null;
        webLabelAndTextField = null;
        initialize();
    }

    private void initialize() {
        setJMenuBar(getBasicMenu());
        setFrameIcon(new ImageIcon(getClass().getResource("/org/jpgolay/gui/images/arrowRight18x18.png")));
        setTitle("AGENCES");
        setSize(330, 420);
        setContentPane(getJContentPane());
    }

    private JPanel getJContentPane() {
        if (jContentPane == null) {
            jContentPane = new JPanel();
            jContentPane.setLayout(new BorderLayout());
            jContentPane.add(getIconBar(), "North");
            jContentPane.add(getMainPanel(), "Center");
        }
        return jContentPane;
    }

    private BasicMenu getBasicMenu() {
        if (basicMenu == null) {
            basicMenu = new BasicMenu();
        }
        return basicMenu;
    }

    private IconBar getIconBar() {
        if (iconBar == null) {
            iconBar = new IconBar();
        }
        return iconBar;
    }

    private JPanel getMainPanel() {
        if (mainPanel == null) {
            mainPanel = new JPanel();
            mainPanel.setLayout(new BorderLayout());
            mainPanel.add(getAgencyListLabelAndComboBox(), "North");
            mainPanel.add(getJTabbedPane(), "Center");
        }
        return mainPanel;
    }

    private LabelAndComboBox getAgencyListLabelAndComboBox() {
        if (agencyListLabelAndComboBox == null) {
            agencyListLabelAndComboBox = new LabelAndComboBox();
            agencyListLabelAndComboBox.setLabel("Liste des agences");
        }
        return agencyListLabelAndComboBox;
    }

    private JTabbedPane getJTabbedPane() {
        if (jTabbedPane == null) {
            jTabbedPane = new JTabbedPane();
            jTabbedPane.addTab("Coordonn\351es", null, getAddressPanel(), null);
            jTabbedPane.addTab("Infos", null, getInfosPanel(), null);
        }
        return jTabbedPane;
    }

    private JPanel getAddressPanel() {
        if (addressPanel == null) {
            FlowLayout flowLayout1 = new FlowLayout();
            addressPanel = new JPanel();
            addressPanel.setLayout(flowLayout1);
            flowLayout1.setVgap(2);
            addressPanel.add(getCompanyLabelAndTextField(), null);
            addressPanel.add(getStatusLabelAndComboBox(), null);
            addressPanel.add(getAddrLn1LabelAndTextField(), null);
            addressPanel.add(getAddrLn2LabelAndTextField(), null);
            addressPanel.add(getCityLabelAndTextField(), null);
            addressPanel.add(getZipLabelAndTextField(), null);
            addressPanel.add(getCountryLabelAndTextField(), null);
            addressPanel.add(getTel1LabelAndTextField(), null);
            addressPanel.add(getFax1LabelAndTextField(), null);
            addressPanel.add(getEmailLabelAndTextField(), null);
        }
        return addressPanel;
    }

    private LabelAndTextField getCompanyLabelAndTextField() {
        if (companyLabelAndTextField == null) {
            companyLabelAndTextField = new LabelAndTextField();
            companyLabelAndTextField.setLabel("Raison social");
        }
        return companyLabelAndTextField;
    }

    private LabelAndComboBox getStatusLabelAndComboBox() {
        if (statusLabelAndComboBox == null) {
            statusLabelAndComboBox = new LabelAndComboBox();
            statusLabelAndComboBox.setLabel("Civilit\351");
            statusLabelAndComboBox.setList(MEUtility.STATUS);
        }
        return statusLabelAndComboBox;
    }

    private LabelAndTextField getAddrLn1LabelAndTextField() {
        if (addrLn1LabelAndTextField == null) {
            addrLn1LabelAndTextField = new LabelAndTextField();
            addrLn1LabelAndTextField.setLabel("Adresse");
        }
        return addrLn1LabelAndTextField;
    }

    private LabelAndTextField getAddrLn2LabelAndTextField() {
        if (addrLn2LabelAndTextField == null) {
            addrLn2LabelAndTextField = new LabelAndTextField();
            addrLn2LabelAndTextField.setLabel(" ");
        }
        return addrLn2LabelAndTextField;
    }

    private LabelAndTextField getCityLabelAndTextField() {
        if (cityLabelAndTextField == null) {
            cityLabelAndTextField = new LabelAndTextField();
            cityLabelAndTextField.setLabel("Ville");
        }
        return cityLabelAndTextField;
    }

    private LabelAndTextField getZipLabelAndTextField() {
        if (zipLabelAndTextField == null) {
            zipLabelAndTextField = new LabelAndTextField();
            zipLabelAndTextField.setLabel("Code postal");
        }
        return zipLabelAndTextField;
    }

    private LabelAndTextField getCountryLabelAndTextField() {
        if (countryLabelAndTextField == null) {
            countryLabelAndTextField = new LabelAndTextField();
            countryLabelAndTextField.setLabel("Pays");
        }
        return countryLabelAndTextField;
    }

    private LabelAndTextField getTel1LabelAndTextField() {
        if (tel1LabelAndTextField == null) {
            tel1LabelAndTextField = new LabelAndTextField();
            tel1LabelAndTextField.setLabel("T\351l");
        }
        return tel1LabelAndTextField;
    }

    private LabelAndTextField getFax1LabelAndTextField() {
        if (fax1LabelAndTextField == null) {
            fax1LabelAndTextField = new LabelAndTextField();
            fax1LabelAndTextField.setLabel("Fax");
        }
        return fax1LabelAndTextField;
    }

    private LabelAndTextField getEmailLabelAndTextField() {
        if (emailLabelAndTextField == null) {
            emailLabelAndTextField = new LabelAndTextField();
            emailLabelAndTextField.setLabel("Email");
        }
        return emailLabelAndTextField;
    }

    private JPanel getInfosPanel() {
        if (infosPanel == null) {
            infosPanel = new JPanel();
            infosPanel.add(getSiretLabelAndTextField(), null);
            infosPanel.add(getNafLabelAndTextField(), null);
            infosPanel.add(getGlnLabelAndTextField(), null);
            infosPanel.add(getNotesLabelAndTextField(), null);
            infosPanel.add(getTel2LabelAndTextField(), null);
            infosPanel.add(getFax2LabelAndTextField(), null);
            infosPanel.add(getFax3LabelAndTextField(), null);
            infosPanel.add(getTel3LabelAndTextField(), null);
            infosPanel.add(getWebLabelAndTextField(), null);
        }
        return infosPanel;
    }

    private LabelAndTextField getSiretLabelAndTextField() {
        if (siretLabelAndTextField == null) {
            siretLabelAndTextField = new LabelAndTextField();
            siretLabelAndTextField.setLabel("N\260 Siret");
        }
        return siretLabelAndTextField;
    }

    private LabelAndTextField getNafLabelAndTextField() {
        if (nafLabelAndTextField == null) {
            nafLabelAndTextField = new LabelAndTextField();
            nafLabelAndTextField.setLabel("N\260 Naf");
        }
        return nafLabelAndTextField;
    }

    private LabelAndTextField getGlnLabelAndTextField() {
        if (glnLabelAndTextField == null) {
            glnLabelAndTextField = new LabelAndTextField();
            glnLabelAndTextField.setLabel("N\260 GLN");
        }
        return glnLabelAndTextField;
    }

    private LabelAndTextField getNotesLabelAndTextField() {
        if (notesLabelAndTextField == null) {
            notesLabelAndTextField = new LabelAndTextField();
            notesLabelAndTextField.setLabel("Notes");
        }
        return notesLabelAndTextField;
    }

    private LabelAndTextField getTel2LabelAndTextField() {
        if (tel2LabelAndTextField == null) {
            tel2LabelAndTextField = new LabelAndTextField();
            tel2LabelAndTextField.setLabel("T\351l 2");
        }
        return tel2LabelAndTextField;
    }

    private LabelAndTextField getTel3LabelAndTextField() {
        if (tel3LabelAndTextField == null) {
            tel3LabelAndTextField = new LabelAndTextField();
            tel3LabelAndTextField.setLabel("Fax 3");
        }
        return tel3LabelAndTextField;
    }

    private LabelAndTextField getFax2LabelAndTextField() {
        if (fax2LabelAndTextField == null) {
            fax2LabelAndTextField = new LabelAndTextField();
            fax2LabelAndTextField.setLabel("Fax 2");
        }
        return fax2LabelAndTextField;
    }

    private LabelAndTextField getFax3LabelAndTextField() {
        if (fax3LabelAndTextField == null) {
            fax3LabelAndTextField = new LabelAndTextField();
            fax3LabelAndTextField.setLabel("T\351l 3");
        }
        return fax3LabelAndTextField;
    }

    private LabelAndTextField getWebLabelAndTextField() {
        if (webLabelAndTextField == null) {
            webLabelAndTextField = new LabelAndTextField();
            webLabelAndTextField.setLabel("Site web");
        }
        return webLabelAndTextField;
    }

    public BasicMenu getMenuPanel() {
        return getBasicMenu();
    }

    public IconBar getIconBarPanel() {
        return getIconBar();
    }

    public int getAgencyListValue() {
        return getAgencyListLabelAndComboBox().getSelectedIndex();
    }

    public void setAgencyListValue(int index) {
        getAgencyListLabelAndComboBox().setSelectedIndex(index);
    }

    public void setAgencyListValue(String list[]) {
        getAgencyListLabelAndComboBox().setList(list);
    }

    public JComboBox getAgencyListComboBox() {
        return getAgencyListLabelAndComboBox().getComboBox();
    }

    public String getCompanyValue() {
        return getCompanyLabelAndTextField().getVal();
    }

    public void setCompanyValue(String txt) {
        getCompanyLabelAndTextField().setVal(txt);
    }

    public String getStatusValue() {
        return (String) getStatusLabelAndComboBox().getComboBox().getSelectedItem();
    }

    public void setStatusValue(String txt) {
        getStatusLabelAndComboBox().getComboBox().setSelectedItem(txt);
    }

    public String getAddrLn1Value() {
        return getAddrLn1LabelAndTextField().getVal();
    }

    public void setAddrLn1Value(String txt) {
        getAddrLn1LabelAndTextField().setVal(txt);
    }

    public String getAddrLn2Value() {
        return getAddrLn2LabelAndTextField().getVal();
    }

    public void setAddrLn2Value(String txt) {
        getAddrLn2LabelAndTextField().setVal(txt);
    }

    public String getCityValue() {
        return getCityLabelAndTextField().getVal();
    }

    public void setCityValue(String txt) {
        getCityLabelAndTextField().setVal(txt);
    }

    public String getZipValue() {
        return getZipLabelAndTextField().getVal();
    }

    public void setZipValue(String txt) {
        getZipLabelAndTextField().setVal(txt);
    }

    public String getCountryValue() {
        return getCountryLabelAndTextField().getVal();
    }

    public void setCountryValue(String txt) {
        getCountryLabelAndTextField().setVal(txt);
    }

    public String getTel1Value() {
        return getTel1LabelAndTextField().getVal();
    }

    public void setTel1Value(String txt) {
        getTel1LabelAndTextField().setVal(txt);
    }

    public String getFax1Value() {
        return getFax1LabelAndTextField().getVal();
    }

    public void setFax1Value(String txt) {
        getFax1LabelAndTextField().setVal(txt);
    }

    public String getEmailValue() {
        return getEmailLabelAndTextField().getVal();
    }

    public void setEmailValue(String txt) {
        getEmailLabelAndTextField().setVal(txt);
    }

    public String getSiretValue() {
        return getSiretLabelAndTextField().getVal();
    }

    public void setSiretValue(String txt) {
        getSiretLabelAndTextField().setVal(txt);
    }

    public String getNafValue() {
        return getNafLabelAndTextField().getVal();
    }

    public void setNafValue(String txt) {
        getNafLabelAndTextField().setVal(txt);
    }

    public String getGlnValue() {
        return getGlnLabelAndTextField().getVal();
    }

    public void setGlnValue(String txt) {
        getGlnLabelAndTextField().setVal(txt);
    }

    public String getNotesValue() {
        return getNotesLabelAndTextField().getVal();
    }

    public void setNotesValue(String txt) {
        getNotesLabelAndTextField().setVal(txt);
    }

    public String getTel2Value() {
        return getTel2LabelAndTextField().getVal();
    }

    public void setTel2Value(String txt) {
        getTel2LabelAndTextField().setVal(txt);
    }

    public String getTel3Value() {
        return getTel3LabelAndTextField().getVal();
    }

    public void setTel3Value(String txt) {
        getTel3LabelAndTextField().setVal(txt);
    }

    public String getFax2Value() {
        return getFax2LabelAndTextField().getVal();
    }

    public void setFax2Value(String txt) {
        getFax2LabelAndTextField().setVal(txt);
    }

    public String getFax3Value() {
        return getFax3LabelAndTextField().getVal();
    }

    public void setFax3Value(String txt) {
        getFax3LabelAndTextField().setVal(txt);
    }

    public String getWebValue() {
        return getWebLabelAndTextField().getVal();
    }

    public void setWebValue(String txt) {
        getWebLabelAndTextField().setVal(txt);
    }

    public void cleanField() {
        setCompanyValue("");
        setStatusValue("");
        setAddrLn1Value("");
        setAddrLn2Value("");
        setCityValue("");
        setZipValue("");
        setCountryValue("");
        setTel1Value("");
        setFax1Value("");
        setEmailValue("");
        setSiretValue("");
        setNafValue("");
        setGlnValue("");
        setNotesValue("");
        setTel2Value("");
        setTel3Value("");
        setFax2Value("");
        setFax3Value("");
        setWebValue("");
    }

    public void setEnabledField(boolean b) {
        getCompanyLabelAndTextField().getTextField().setEditable(b);
        getStatusLabelAndComboBox().getComboBox().setEnabled(b);
        getAddrLn1LabelAndTextField().getTextField().setEditable(b);
        getAddrLn2LabelAndTextField().getTextField().setEditable(b);
        getCityLabelAndTextField().getTextField().setEditable(b);
        getZipLabelAndTextField().getTextField().setEditable(b);
        getCountryLabelAndTextField().getTextField().setEditable(b);
        getTel1LabelAndTextField().getTextField().setEditable(b);
        getFax1LabelAndTextField().getTextField().setEditable(b);
        getEmailLabelAndTextField().getTextField().setEditable(b);
        getSiretLabelAndTextField().getTextField().setEditable(b);
        getNafLabelAndTextField().getTextField().setEditable(b);
        getGlnLabelAndTextField().getTextField().setEditable(b);
        getNotesLabelAndTextField().getTextField().setEditable(b);
        getTel2LabelAndTextField().getTextField().setEditable(b);
        getTel3LabelAndTextField().getTextField().setEditable(b);
        getFax2LabelAndTextField().getTextField().setEditable(b);
        getFax3LabelAndTextField().getTextField().setEditable(b);
        getWebLabelAndTextField().getTextField().setEditable(b);
    }
    private JPanel jContentPane;
    private BasicMenu basicMenu;
    private IconBar iconBar;
    private JPanel mainPanel;
    private LabelAndComboBox agencyListLabelAndComboBox;
    private JTabbedPane jTabbedPane;
    private JPanel addressPanel;
    private LabelAndTextField companyLabelAndTextField;
    private LabelAndComboBox statusLabelAndComboBox;
    private LabelAndTextField addrLn1LabelAndTextField;
    private LabelAndTextField addrLn2LabelAndTextField;
    private LabelAndTextField cityLabelAndTextField;
    private LabelAndTextField zipLabelAndTextField;
    private LabelAndTextField countryLabelAndTextField;
    private LabelAndTextField tel1LabelAndTextField;
    private LabelAndTextField fax1LabelAndTextField;
    private LabelAndTextField emailLabelAndTextField;
    private JPanel infosPanel;
    private LabelAndTextField siretLabelAndTextField;
    private LabelAndTextField nafLabelAndTextField;
    private LabelAndTextField glnLabelAndTextField;
    private LabelAndTextField notesLabelAndTextField;
    private LabelAndTextField tel2LabelAndTextField;
    private LabelAndTextField tel3LabelAndTextField;
    private LabelAndTextField fax2LabelAndTextField;
    private LabelAndTextField fax3LabelAndTextField;
    private LabelAndTextField webLabelAndTextField;
}
